package org.fund.base_service.service.impl;

import com.github.pagehelper.PageHelper;
import org.fund.base_service.domain.TransactionRecord;
import org.fund.base_service.domain.input.base.PageDomain;
import org.fund.base_service.mapper.TransactionRecordMapper;
import org.fund.base_service.service.TransactionRecordService;
import org.fund.common.util.SecurityUtils;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 买卖记录(TransactionRecord)表服务实现类
 *
 * @author makejava
 * @since 2022-03-13 01:28:45
 */
@Service
public class TransactionRecordServiceImpl implements TransactionRecordService {
    @Autowired
    private TransactionRecordMapper transactionRecordMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TransactionRecord queryById(Integer id) {
        return this.transactionRecordMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @Override
    public PageInfo<TransactionRecord> queryByPage(PageDomain pageDomain) {
        PageHelper.startPage(pageDomain.getPageNum(), pageDomain.getPageSize());
        List<TransactionRecord> records = transactionRecordMapper.queryAll(SecurityUtils.getUserId());
        return new PageInfo<>(records);
    }

    /**
     * 新增数据
     *
     * @param transactionRecord 实例对象
     * @return 实例对象
     */
    @Override
    public TransactionRecord insert(TransactionRecord transactionRecord) {
        this.transactionRecordMapper.insert(transactionRecord);
        return transactionRecord;
    }

    /**
     * 修改数据
     *
     * @param transactionRecord 实例对象
     * @return 实例对象
     */
    @Override
    public TransactionRecord update(TransactionRecord transactionRecord) {
        this.transactionRecordMapper.update(transactionRecord);
        return this.queryById(transactionRecord.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.transactionRecordMapper.deleteById(id) > 0;
    }

    @Override
    public List<TransactionRecord> queryByPositionId(Integer pid) {
        return transactionRecordMapper.queryByPositionId(pid,SecurityUtils.getUserId());
    }
}
